function ajax(mender, url, can) {
    var str = ''
    for (const key in can) {
        str += `${key}=${can[key]}&`
    }
    str = str.slice(0, str.length - 1)
    return new Promise((resolve, reject) => {
        var xhr = new XMLHttpRequest()
        xhr.open(mender, mender == 'get' ? url + '?' + str : url)
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4) {
                resolve(JSON.parse(xhr.responseText))
            }
        }
        xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded')
        xhr.send(mender == 'get' ? null : str)
    })
}